﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DreamBox.Admin.SystemSettings
{
    public partial class WebSite : BLL.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DAL.PSelect ps = new DAL.PSelect();
                DataTable dt = ps.Select("dbox_Config", "*", "ConfigID=1");
                if (dt.Rows.Count > 0)
                {
                    SiteName.Text = dt.Rows[0]["SiteName"].ToString();
                    SiteUrl.Text = dt.Rows[0]["SiteUrl"].ToString();
                    SiteTitle.Text = dt.Rows[0]["Title"].ToString();
                    KeyWords.Text = dt.Rows[0]["KeyWords"].ToString();
                    Description.Text = dt.Rows[0]["Description"].ToString();
                    ICP.Text = dt.Rows[0]["ICP"].ToString();
                    CopyRight.Text = dt.Rows[0]["CopyRight"].ToString();
                    RegisterOpenMsg.Text = dt.Rows[0]["RegisterOpenMsg"].ToString();
                    SiteOpenMsg.Text = dt.Rows[0]["SiteOpenMsg"].ToString();
                    IsLoginMsg.Text = dt.Rows[0]["IsLoginMsg"].ToString();
                    //
                    boxListOptions.Items[0].Selected = bool.Parse(dt.Rows[0]["RegisterOpen"].ToString());

                    boxListOptions.Items[1].Selected = bool.Parse(dt.Rows[0]["SiteOpen"].ToString());
                    boxListOptions.Items[2].Selected = bool.Parse(dt.Rows[0]["IsLogin"].ToString());
                }
            }
        }

        protected void btnPost_Click(object sender, EventArgs e)
        {
            Model.SiteConfig m = new Model.SiteConfig();
            m.ConfigID = 1;
            m.SiteName = SiteName.Text;
            m.SiteUrl = SiteUrl.Text;
            m.Title = SiteTitle.Text;
            m.KeyWords = KeyWords.Text;
            m.Description = Description.Text;
            m.ICP = ICP.Text;
            m.CopyRight = CopyRight.Text;
            m.RegisterOpen = boxListOptions.Items[0].Selected;
            m.SiteOpen = boxListOptions.Items[1].Selected;
            m.IsLogin = boxListOptions.Items[2].Selected;
            //
            m.RegisterOpenMsg = RegisterOpenMsg.Text;
            m.SiteOpenMsg = SiteOpenMsg.Text;
            m.IsLoginMsg = IsLoginMsg.Text;

            DAL.Config.SiteConfig config = new DAL.Config.SiteConfig();
            if (config.Update(m))
            {
                BLL.Admin.Tips.DetailedTips(this, "系统设置信息更新成功", "/SystemSettings/WebSite.aspx", "1");
            }
        }
    }
}